package gang.org.springframework.framework.metadata;

import gang.org.springframework.framework.type.GangMethodMetadata;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
 * @author gang.chen
 * @since 2021/6/19 19:36
 */
public class GangStandardAnnotationMetadata extends GangStandardClassMetadata implements GangAnnotationMetadata
{
    private final GangMergedAnnotations mergedAnnotations;
    private final boolean nestedAnnotationsAsMap;

    /**
     * @param introspectedClass
     *      {@link gang.org.springframework.boot.autoconfigure.GEnableAutoConfiguration}
     *      {@link com.gang.mars.boot.SpringbootManualApplication}
     * @param nestedAnnotationsAsMap default value is true
     * */
    public GangStandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap)
    {
        super(introspectedClass);
        //####################################################
        //重点
        //1, MergedAnnotations 该接口对象，继承自Iterable
        //2, MergedAnnotations->GangTypeMappedAnnotations
        //####################################################
        this.mergedAnnotations = GangMergedAnnotations.from(introspectedClass, GangMergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS,GangRepeatableContainers.none());

        this.nestedAnnotationsAsMap= nestedAnnotationsAsMap;
    }

    /**
     * @param introspectedClass
     *        {@link gang.org.springframework.boot.autoconfigure.GEnableAutoConfiguration}
     *        {@link com.gang.mars.boot.SpringbootManualApplication}
     * */
    public static GangAnnotationMetadata from(Class<?> introspectedClass)
    {
        return new GangStandardAnnotationMetadata(introspectedClass,true);
    }

    /**
     * @param annotationName 注解名称 -> gang.org.springframework.framework.annotation.GComponentScan
     * @param classValuesAsString 类值转字符 -> true
     * */
    @Override
    public Map<String, Object> getAnnotationAttribute(String annotationName, boolean classValuesAsString) {
        if (this.nestedAnnotationsAsMap)
        {
            //元数据AnnotationMetadata 父类 AnnotatedTypeMetadata
            return GangAnnotationMetadata.super.getAnnotationAttribute(annotationName,classValuesAsString);
        }
        return null;
    }

    @Override
    public GangMergedAnnotations getAnnotations() {
        return this.mergedAnnotations;
    }

    @Override
    public String[] getMemberClassNames() {
        //TODO
        return new String[0];
    }

    /**
     * TODO
     * */
    @Override
    public Set<GangMethodMetadata> getAnnotatedMethods(String annotationName) {
        return Collections.emptySet();
    }
}
